package com.bailiban.controller;

import com.bailiban.entity.Orders;
import com.bailiban.entity.Syslog;
import com.bailiban.service.OrdersService;
import com.bailiban.service.SyslogService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.security.RolesAllowed;

/**
 * @author zhulang
 * @Classname OrdersController
 * @Description OrdersController
 */
@Controller
@RequestMapping("orders")
public class OrdersController {
    @Autowired
    private OrdersService ordersService;

    @GetMapping("findAll")
    @RolesAllowed({"USER", "ADMIN"})
    public ModelAndView findAll(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "3") Integer size) {
        ModelAndView modelAndView = new ModelAndView();
        PageInfo pageInfo = ordersService.findAll(page, size);
        modelAndView.setViewName("orders-list");
        modelAndView.addObject("ordersP", pageInfo);
        return modelAndView;
    }

    @GetMapping("findById")
    public ModelAndView findById(Integer id) {
        ModelAndView modelAndView = new ModelAndView();
        Orders orders = ordersService.queryById(id);
        modelAndView.setViewName("order-show");
        modelAndView.addObject("orders", orders);
        return modelAndView;
    }
}
